package util;

import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

public class MongoUtil1 {
    //获得database
    public static MongoDatabase getDB() {
        MongoClient client = new MongoClient(new ServerAddress("localhost", 27017) );
        MongoDatabase db = client.getDatabase("gaohui");
        return db;
    }
    //获得collection
    public static MongoCollection<Document> getCollection(String collectionName) {
        MongoDatabase db = getDB();
        MongoCollection<Document> collection = db.getCollection(collectionName);
        return collection;
    }

}
